//
//  FactoryListViewController.m
//  quickBatchManager
//
//  Created by jack on 15/10/10.
//  Copyright © 2015年 jack. All rights reserved.
//

#import "FactoryListViewController.h"
#import "FactoryOrderingViewController.h"
@interface FactoryListViewController ()
{
    NSMutableArray *datas;
    ProductModel *product;
}

@end

@implementation FactoryListViewController
@synthesize paramsModeNo;
- (void)viewDidLoad {
    [super viewDidLoad];
    LKDBHelper *helper = [LKDBHelper getUsingLKDBHelper];
    product=[AppService getProductByNo:paramsModeNo];
    datas = [helper search:[FactoryProductInfoModel class] where:[NSString stringWithFormat:@"productId=%ld group by date",product.productId] orderBy:nil offset:0 count:0];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(datas!=nil &&[datas count]>0)
    {
        return [datas count];
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
       static NSString *CMainCell = @"defaultCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CMainCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1  reuseIdentifier: CMainCell];
    }
    FactoryProductInfoModel *model = [datas objectAtIndex:indexPath.row];
    cell.textLabel.text = [model.date substringToIndex:[model.date rangeOfString:@" "].location];
    
    
    double number = [FactoryProductInfoModel sumWithWhere:@"factoryProductNumber" where:[NSString stringWithFormat:@"date='%@'",model.date]];
    
    cell.detailTextLabel.text = [ToolUtils numberToStr:number];
    [cell.detailTextLabel setTextColor:[UIColor blackColor]];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self dismissViewControllerAnimated:YES completion:nil];
    FactoryProductInfoModel *model = [datas objectAtIndex:indexPath.row];
    FactoryOrderingViewController *factoryOrderingVC = [[FactoryOrderingViewController alloc] init];
   // factoryOrderingVC.delegate = self;
    factoryOrderingVC.isEdit = YES;
    factoryOrderingVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    factoryOrderingVC.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
    self.definesPresentationContext = YES;
    factoryOrderingVC.paramsModelNo = product.modelNo;
    factoryOrderingVC.date = model.date;
    [_baseCol presentViewController:factoryOrderingVC animated:YES completion:nil];
}

@end
